package com.itheima.springbootcondition.condition;


import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class ClassCondition implements Condition {
    /**
     *
     * @param context 上下文对象,用于获取环境,IOC容器,classloader对象
     * @param metdata 注解元对象,可以用户获取注解定义的属性值
     * @return
     */

    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //1.需求:导入Jedis坐标后创建bean
        //Class.forName加载字节码,判断redis.client.jedis.Jedis文件是否存在
        boolean flag = true;
        try {
            Class<?> cls = Class.forName("redis.clients.jedis.Jedis");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            flag=false;
        }

        return flag;
    }
}
